package net.jblog.struts.tools;

import net.jblog.data.model.Category;
import net.jblog.data.model.Post;
import net.jblog.struts.backoffice.form.CategoryForm;
import net.jblog.struts.backoffice.form.PostForm;

public class BeanUtils {

	public static void copyPropertiesFromPostBeanToPostForm(Post bean, PostForm form) {
		form.setId(bean.getId());
		form.setTitle(bean.getTitle());
		form.setContent(bean.getContent().getValue());
		form.setUrl((bean.getUrl()!=null)?bean.getUrl().getValue():null);
		if(bean.getCategory() != null) {
			form.setCategory(bean.getCategory().getId());
			form.setCategoryName(bean.getCategory().getName());
		}
		
		form.setDateCreated(bean.getDateCreated());
		form.setDateModified(bean.getDateModified());
		form.setDatePublished(bean.getDatePublished());
		
		form.setState(bean.getState());
	}
	
	public static void copyPropertiesFromCategoryBeanToCategoryForm(Category bean, CategoryForm form) {
		form.setId(bean.getId());
		form.setName(bean.getName());
		form.setParent((bean.getParent()==null || bean.getParent().longValue()==0)?null:bean.getParent());
		form.setDescription((bean.getDescription()!=null)?bean.getDescription().getValue():null);
	}
}
